FROM alpine:3.16

ENV PHPIZE_DEPS="autoconf dpkg-dev dpkg file tar zip g++ gcc libc-dev make pkgconf re2c pcre-dev pcre2-dev zlib-dev libtool automake"

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories

COPY ./run.sh /run.sh

RUN apk update \
	&& apk add  php8 php8-pear php8-dev openssl curl bash ca-certificates libaio-dev openssl-dev curl-dev \
                php8-mysqli php8-pdo_mysql php8-mbstring php8-json php8-zlib php8-gd php8-intl php8-session php8-fpm \
                php8-curl php8-posix php8-fileinfo php8-simplexml php8-opcache php8-sodium \
                php8-tokenizer php8-ctype php8-bcmath php8-openssl php8-dom \ 
                php8-iconv php8-sockets php8-zip php8-pcntl php8-xmlwriter php8-xmlreader php8-redis php8-xml php8-phar \
                php8-pecl-event \
    && apk add --no-cache --virtual .build-deps $PHPIZE_DEPS \
	&& apk --no-cache add tzdata \
    && cp "/usr/share/zoneinfo/Asia/Shanghai" /etc/localtime \
    && echo "Asia/Shanghai" > /etc/timezone \
    && update-ca-certificates \
    && mkdir /www \
    && sed 's/user = nobody/user = root/g' /etc/php8/php-fpm.d/www.conf | sed 's/group = nobody/group = root/g'| sed 's/127.0.0.1/0.0.0.0/g' | sed 's/pm.max_children = 5/pm.max_children = 30/g' | sed 's/pm = dynamic/pm = static/g' > /tmp/www.conf \
    && mv /tmp/www.conf /etc/php8/php-fpm.d/www.conf \
    && apk add gnu-libiconv libstdc++ --no-cache --repository http://mirrors.aliyun.com/alpine/edge/community/ --allow-untrusted \
    && sed 's/;opcache.enable=1/opcache.enable=1/g' /etc/php8/php.ini | sed 's/;opcache.validate_timestamps=1/opcache.validate_timestamps=0/g' | sed 's/;opcache.memory_consumption=128/opcache.memory_consumption=128/g' | sed 's/;opcache.interned_strings_buffer=8/opcache.interned_strings_buffer=8/g' | sed 's/;opcache.max_accelerated_files=10000/opcache.max_accelerated_files=10000/g' > /tmp/php.ini \
    && mv /tmp/php.ini /etc/php8/php.ini \
    && ln -s /usr/sbin/php-fpm8 /usr/sbin/php-fpm \
    #&& ln -s /usr/bin/php8 /usr/bin/php \
    #&& ln -s /usr/bin/phar8 /usr/bin/phar \
    #&& ln -s /usr/bin/php-config8 /usr/bin/php-config \
    #&& ln -s /usr/bin/phpize8 /usr/bin/phpize \
    && chmod +x /run.sh \
    && wget https://mirrors.tencent.com/composer/composer.phar \
    && mv composer.phar  /usr/local/bin/composer \
    && chmod 755 /usr/local/bin/composer 
     # ---------- clear works ----------
    #&& apk del .build-deps \
    #&& rm -rf /var/cache/apk/* /tmp/* /usr/share/man /usr/local/bin/php* \
    #&& composer config -g repos.packagist composer https://mirrors.tencent.com/composer/

#RUN apk add --no-cache nginx \
#	&& touch /run/nginx/nginx.pid \
#	&& sed 's/user nginx;/user root;/g' /etc/nginx/nginx.conf | sed 's/#gzip on;/gzip on;/g' > /tmp/nginx.conf \
#	&& mv /tmp/nginx.conf /etc/nginx/nginx.conf 

#COPY ./nginx.conf /etc/nginx/http.d/default.conf

WORKDIR /www

EXPOSE 8787 9000

CMD ["/run.sh"]